const {
  $util,
} = getApp();
Page({
  data: {},
  onLoad(opts) {
    const {
      id,
      openType,
    } = opts;
    this.setData(opts, () => {
      this.loadDetail(id, openType);
    });
  },
  onShow() {
    let wxData = wx.getStorageSync('qyUserInfo') || {};
    this.setData(wxData);
    this.setData({
      isSaaS: wx.getStorageSync('isSaaS'),
    })
  },
  loadDetail(id, openType) {
    $util.request({
      url: 'entry/wxapp/partyman.home.getadvicedetails',
      data: {
        id,
        type: openType,
      },
      success: (res) => {
        this.setData({
          detail: res.data,
          loaded: true,
        });
      },
    });
  },
  onTap(e) {
    console.log(e);
    const type = e.currentTarget.dataset.type;
    if (!type) return;
    const id = this.data.id;
    $util.request({
      url: 'entry/wxapp/partyman.home.judgeadvice',
      data: {
        id,
        type,
      },
      success: (res) => {
        wx.showToast({
          title: '操作成功',
          mask: true,
          icon: 'none',
          duration: 1000,
        });
        setTimeout(() => {
          wx.navigateBack();
        }, 1500);
      },
    });
  },
});
